package gui;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import client.ClientConsole;

import logic.Message;


public class GraduateWindow extends JPanel implements ActionListener{
	private JPanel mainPanel,searchPanel,topPanel,bottomPanel;
	private JTextField userId;
	private JButton graduateButton;
	private JButton back;
	private JLabel confirmationLabel,userIdLabel;
	GridBagConstraints gbc = new GridBagConstraints();
	public GraduateWindow()
	{
			super();
			setSize(300, 300);
			mainPanel=new JPanel();
			mainPanel.setLayout(new BorderLayout());
			searchPanel=new JPanel(new GridBagLayout());
			userIdLabel=new JLabel("User ID: ");
			gbc = new GridBagConstraints();
			gbc.gridx=0;
			gbc.gridy=0;
			searchPanel.add(userIdLabel,gbc);
			userId=new JTextField(20);
			gbc = new GridBagConstraints();
			gbc.gridx=1;
			gbc.gridy=0;
			gbc.insets= new Insets(5,5,5,5);
			searchPanel.add(userId,gbc);
						
			gbc = new GridBagConstraints();
			gbc.gridx=0;
			gbc.gridy=2;
			gbc.gridwidth=2;
			gbc.insets= new Insets(5,5,5,5);

			graduateButton= new JButton("Lock Graduated");
			searchPanel.add(graduateButton,gbc);
			mainPanel.add(searchPanel,BorderLayout.NORTH);
			topPanel=new JPanel();
			confirmationLabel=new JLabel();
			topPanel.add(confirmationLabel);
			mainPanel.add(topPanel,BorderLayout.CENTER);
			bottomPanel=new JPanel();
			back=new JButton("Back");
			bottomPanel.add(back);
			mainPanel.add(bottomPanel,BorderLayout.SOUTH);
			add(mainPanel);
			graduateButton.addActionListener(this);
			back.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource()==back)
		{
			this.setVisible(false);
			ClientConsole.aFrame.setContentPane(new LibraryManagerWindow());
		}
		else if (ae.getSource()==graduateButton)
		{
			Message msg=new Message("ExternalLockRequest",Integer.parseInt(userId.getText()));
			ClientConsole.HandleMessageFromGui(msg);
			confirmationLabel.setText("Request sent to sever");
			confirmationLabel.setVisible(true);
			
		}

	}

}
